﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using eGrid_App;
using ESRI.ArcGIS.Client;

namespace GISforTT_Test
{
    [TestClass]
    public class MapLayersManagerTest
    {
        [TestMethod]
        public void MapLayersManagerDefaultLayersTest()
        {
            LayerCollection layers = MapLayersManager.Instance.MapLayers;
            
            MapLayersManager.Instance.ResetDefaultLayers();
            //We should have 6 default map layers to start with
            Assert.AreEqual(6, layers.Count);
            Assert.AreEqual("ShadedRelief", layers[0].ID);
            Assert.AreEqual("Imagery", layers[1].ID);
            Assert.AreEqual("StreetMap", layers[2].ID);
            Assert.AreEqual("TroubleTicketsLayer", layers[3].ID);
            Assert.AreEqual("VehiclesLayer", layers[4].ID);
            Assert.AreEqual("AnnotationsLayer", layers[5].ID);
        }

        [TestMethod]
        public void AddLayerObjectTest()
        {
            ArcGISTiledMapServiceLayer newLayer = new ArcGISTiledMapServiceLayer();
            newLayer.ID = "NewLayer";
            MapLayersManager.Instance.AddLayer(newLayer);
            //Now we should have 7 layers
            Assert.AreEqual(7, MapLayersManager.Instance.MapLayers.Count);
            Assert.AreEqual("NewLayer", MapLayersManager.Instance.MapLayers[6].ID);
        }

        [TestMethod]
        public void AddLayerWithParamsTest()
        {
            MapLayersManager.Instance.AddLayer("NewLayer2", "http://www.example.com");
            //now we should have 8 layers
            Assert.AreEqual(8, MapLayersManager.Instance.MapLayers.Count);

            ArcGISTiledMapServiceLayer newlayer = (ArcGISTiledMapServiceLayer) MapLayersManager.Instance.MapLayers[7];
            Assert.AreEqual("NewLayer2", newlayer.ID);
            Assert.AreEqual("http://www.example.com", newlayer.Url);
        }

        [TestMethod]
        public void RemoveLayerTest()
        {
            //Removing a layer that does not exist should return false
            Assert.AreEqual(false, MapLayersManager.Instance.RemoveLayer("NoLayer"));
            //No layers should have been removed, we should still have 8 layers
            Assert.AreEqual(6, MapLayersManager.Instance.MapLayers.Count);
            //Removing a layer that exist should return true
            Assert.AreEqual(true, MapLayersManager.Instance.RemoveLayer("Imagery"));
            Assert.AreEqual(5, MapLayersManager.Instance.MapLayers.Count);
            Assert.AreEqual(true, MapLayersManager.Instance.RemoveLayer("ShadedRelief"));
            Assert.AreEqual(true, MapLayersManager.Instance.RemoveLayer("AnnotationsLayer"));
            Assert.AreEqual(3, MapLayersManager.Instance.MapLayers.Count);
        }

        [TestMethod]
        public void CloneLayerTest()
        {
            ArcGISTiledMapServiceLayer originalLayer = new ArcGISTiledMapServiceLayer();
            originalLayer.ID = "OriLayer";
            originalLayer.Url = "http://www.example.com";
            originalLayer.Opacity = 1.0;

            ArcGISTiledMapServiceLayer copiedLayer = (ArcGISTiledMapServiceLayer) MapLayersManager.Instance.CloneLayer(originalLayer);
            Assert.AreEqual(copiedLayer.ID, originalLayer.ID);
            Assert.AreEqual(copiedLayer.Url, originalLayer.Url);
            Assert.AreEqual(copiedLayer.Opacity, originalLayer.Opacity);
        }
    }
}
